Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-18-2008, 10:07 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
replacetext()

I tried Tig's replacetext, but I couldn't get it to work, so I had to create my own. I thought I'd post it here in case anyone wanted to use it.

PHP Code:
function replacetext(txt,a,b) {
  if (
txt.pos(a)<0) return txt;
  
temp.txtpos txt.positions(a);
  
temp.newtxt txt.substring(0,txtpos[0]);
  for (
temp.i=0;i<txtpos.size();i++) {
    
newtxt @= b;
    
newtxt @= txt.substring(txtpos[i]+a.length(),txt.substring(txtpos[i]+a.length()).pos(a));
  }
  return 
newtxt;

Functions simply via:

temp.test = replacetext("Hello\n \"world how\"\n\n are you?","\n",",");

will return Hello, "world how",, are you?(sorry I stole your thing, Tig!)

I don't know how efficient it is, but I got it working so I was happy with it.
Reply With Quote
  #2  
Old 11-18-2008, 10:13 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
i don't get it =o
Reply With Quote
  #3  
Old 11-18-2008, 10:17 PM
Clockwork Clockwork is offline
ᶘ ᵒᴥᵒᶅ...ᶘ ಠᴥಠᶅ❤...ℳℴℯ
Clockwork's Avatar
Join Date: Feb 2007
Location: Pennsylvania
Posts: 2,071
Clockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant future
Quote:
Originally Posted by [email protected] View Post
i don't get it =o
Lets you use quotes and such in chat :o
__________________
Reply With Quote
  #4  
Old 11-18-2008, 10:24 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by [email protected] View Post
i don't get it =o


PHP Code:
function onCreated() {
  
temp.str "epic_underscores^4_life";
  
temp.str replacetext(str"_"" ");  // replace _ with " " (space)
  
temp.str replacetext(str"^"" "); // replace ^ with " " (space)

  
echo(str); // "epic underscores 4 life"

__________________
Reply With Quote
  #5  
Old 11-18-2008, 10:28 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by [email protected] View Post
i don't get it =o
Used to replace text within a string. I originally needed it because I was reading lists of weapons from the WEAPONS folder, and I needed to replace the %057 and such with the appropriate characters.
Reply With Quote
  #6  
Old 11-18-2008, 10:31 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Great job Dusty, I don't really like my replacetext() function anyways. This is probably much better.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #7  
Old 11-18-2008, 10:54 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
ooooh coool =D
Reply With Quote
  #8  
Old 11-18-2008, 11:46 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Good job.
__________________
Reply With Quote
  #9  
Old 01-12-2009, 04:43 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Just what I needed, cheers
Reply With Quote
  #10  
Old 06-19-2009, 04:32 PM
Cubes Cubes is offline
Registered User
Cubes's Avatar
Join Date: Dec 2005
Location: Chesapeake, Virginia
Posts: 498
Cubes is a jewel in the roughCubes is a jewel in the rough
I cannot for the life of me get this to work serverside. I was trying to use it to replace text in a .gmap file. If I trigger serverside -> clientside ->serverside it works but it lags the client for a moment.

PHP Code:
function onActionServerside()
{
  if(
params[0] = "test")
  {
    
temp.testload.loadlines("levels/gmap/temptest.gmap");
    
temp.testload2 replacetext(temp.testload"rofltest""loltest");
    
temp.testload2.savelines("levels/gmap/lolxdd.gmap"0);
  }
}
function 
replacetext(txt,a,b) {
  if (
txt.pos(a)<0)
    return 
txt;
  
temp.txtpos txt.positions(a);
  
temp.newtxt txt.substring(0,txtpos[0]);
  for (
temp.i=0;i<txtpos.size();i++)
  {
    
newtxt @= b;
    
newtxt @= txt.substring(txtpos[i]+a.length(),txt.substring(txtpos[i]+a.length()).pos(a));
  }
  return 
newtxt;
}

//#CLIENTSIDE
function onPlayerChats(){
  
temp.tokens player.chat.tokenize();
  switch(
temp.tokens[0])
  {
    case 
"test":
        
triggerserver("gui"name"test");
      break;
  }

Reply With Quote
  #11  
Old 06-19-2009, 05:20 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
loadlines will return an array, I believe, which is the reason what you are doing is not working. You'd need to do something like...
PHP Code:
temp.testload.loadlines("levels/gmap/temptest.gmap");
for (
temp.i=0;i<temp.testload.size();i++) {
  
temp.testload[i] = replacetext(temp.testload[i], "rofltest""loltest");
}
temp.testload.savelines("levels/gmap/lolxdd.gmap"0); 
Also, you can just use shared.replacetext(x,y,z) instead, as you don't need to add the function.
Reply With Quote
  #12  
Old 06-19-2009, 05:35 PM
Cubes Cubes is offline
Registered User
Cubes's Avatar
Join Date: Dec 2005
Location: Chesapeake, Virginia
Posts: 498
Cubes is a jewel in the roughCubes is a jewel in the rough
I couldn't get the shared.replacetext to work serverside but it would work clientside just fine without looping through it. I'd just trigger back and fourth but it causes to much lag renaming a 30 by 30 gmap and freezes the client for like 2 seconds.
Reply With Quote
  #13  
Old 06-19-2009, 05:37 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
NPC-server probably doesn't have write-rights to the file. Also, have you debugged any? Made sure testload is actually returning anything, to make sure it's not the replacetext? Do some echoes and stuff first.
Reply With Quote
  #14  
Old 06-19-2009, 06:39 PM
Cubes Cubes is offline
Registered User
Cubes's Avatar
Join Date: Dec 2005
Location: Chesapeake, Virginia
Posts: 498
Cubes is a jewel in the roughCubes is a jewel in the rough
Oh I fixed it by doing what you said and I went to let you know but the forums went down again.
Reply With Quote
  #15  
Old 06-19-2009, 08:56 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
shared.replacetext() will not work serverside because it is a part of the clientside function pack; this is a weapon added to players when they log in and pass through the login server, but there is no way for the serverside portion of the script to be carried across servers too.
__________________
Skyld
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:17 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.