I was trying to make a script for my camo change. So I added a model to the map, clip around it, trigger with targetname 'switchcamo'. All good you should say.
I then made a script. New .gsc file with the following content:
if (nextCamoNr >= level.camos.size) { nextCamoNr = 0; }
camo_changer_trigger = getent("switchcamo", "targetname"); camo_changer_trigger sethintstring("Press &&1 to change camo to " + level.camos[nextCamoNr]);
camo_changer_trigger waittill("trigger", player);
player giveWeapon("zombie_colt", "upgraded"); }
I rebuild my MOD and things started to become really messy. I got some weird ass number error which I can't remember, so I decided to remove everything from my map, remove the .gsc file from my MOD folder and comment out the function callings in _zombiemode.gsc. However, still, everytime I go to the map it gives me errors like cannot cast undefined to bool. If I click it away, after a split second it just comes back.
By the way, I don't know what the problem is with my script. I'm not the best scripter, I'm still learning, but is there anything I'm doing wrong?
You have developer set which gives debug information. If i where you i'd fix it but if your lazy and/or don't care if your map is broken you can do "developer 0" in the console.
As far as the script goes, your if condition isn't right. '>=' would be true if nextCamoNr is over or equal to the array size, so the "afterlife" camo would never get selected.
So change:
Code Snippet
Plaintext
if (nextCamoNr >= level.camos.size) { nextCamoNr = 0; }
to:
Code Snippet
Plaintext
if (nextCamoNr > level.camos.size) { nextCamoNr = 0; }
also you don't have the code in a while loop, so it'll only run once.
You have developer set which gives debug information. If i where you i'd fix it but if your lazy and/or don't care if your map is broken you can do "developer 0" in the console.
As far as the script goes, your if condition isn't right. '>=' would be true if nextCamoNr is over or equal to the array size, so the "afterlife" camo would never get selected.
So change:
Code Snippet
Plaintext
if (nextCamoNr >= level.camos.size) { nextCamoNr = 0; }
to:
Code Snippet
Plaintext
if (nextCamoNr > level.camos.size) { nextCamoNr = 0; }
also you don't have the code in a while loop, so it'll only run once.
I wouldn't care about fixing but IDK what the problem is as I've removed everything I made today and it still gives me the errors while yesterday it worked. And I don't think the errors can be caused by the skybox.
Anyways, you're right I totally forgot, thanks for pointing it out.
I wouldn't care about fixing but IDK what the problem is as I've removed everything I made today and it still gives me the errors while yesterday it worked. And I don't think the errors can be caused by the skybox.
Anyways, you're right I totally forgot, thanks for pointing it out.
That giveWeapon is also bad. 2nd param follows weapon file gunmodel1 etc so 2nd param is an int
Didn't know. I was searching for like 50 minutes for the function declaration but couldn't find it anywhere. I just want to change the gun camo (which is ofc. another model). Don't want it to refill ammo though.
Last Edit: August 22, 2015, 04:18:48 pm by JoshZombieBoy
When I use my script, I get the following error when starting up my map:
Code Snippet
Plaintext
script runtime error (see console for details) pair 'undefined' and 'NUMBER' has unmatching types 'undefined' and 'float'
My console gives a shitload of errors:
Just some of them.
All those error's are basicly because of 'sloppy' scripting, variable's arent defined propperly and the result is it's checking against an undefined variable ( and that will Always come out true i believe ).
Now you say the error is about a variable called NUMBER ( i dont see that in your code anywhere ) , so it's prob related to some other script, or you have changed your code allready. Fixing those kind of errors is useally pretty easy, since it'll give you the script + line number and the variable's involved.
Quote
Didn't know. I was searching for like 50 minutes for the function declaration but couldn't find it anywhere. I just want to change the gun camo (which is ofc. another model). Don't want it to refill ammo though.
For changing the cammo do like pwn said and use the number of the model you used in the weaponfile, so for example:
Code Snippet
Plaintext
player giveWeapon("zombie_colt", 2);
Then it will use the gunmodel2 and worldmodel2 from the weaponfile, if that refils your ammo you'd prob have to correct that yourself by getting clip and ammo count before swapping weapons, and then set those numbers on the 'new' gun. Use:
Code Snippet
Plaintext
player getweaponammostock( weapon ) player getweaponammoclip( weapon )
player setweaponammostock( weapon, amount ) player setweaponammoclip( weapon, amount )
All those error's are basicly because of 'sloppy' scripting, variable's arent defined propperly and the result is it's checking against an undefined variable ( and that will Always come out true i believe ).
Now you say the error is about a variable called NUMBER ( i dont see that in your code anywhere ) , so it's prob related to some other script, or you have changed your code allready. Fixing those kind of errors is useally pretty easy, since it'll give you the script + line number and the variable's involved.
For changing the cammo do like pwn said and use the number of the model you used in the weaponfile, so for example:
Code Snippet
Plaintext
player giveWeapon("zombie_colt", 2);
Then it will use the gunmodel2 and worldmodel2 from the weaponfile, if that refils your ammo you'd prob have to correct that yourself by getting clip and ammo count before swapping weapons, and then set those numbers on the 'new' gun. Use:
Code Snippet
Plaintext
player getweaponammostock( weapon ) player getweaponammoclip( weapon )
player setweaponammostock( weapon, amount ) player setweaponammoclip( weapon, amount )
I only called the 2 functions in _zombiemode.gsc the rest i haven't touched. And thanks for your help.